package com.trace.pplos.load.scheduler;

import com.trace.pplos.load.job.DownloadJob;
import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.TriggerBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;

/**
 * Project Name:pplos
 * Package Name:com.trace.pplos.load.scheduler
 *
 * @author：zhouqilin
 * @date：2017/8/6 10:46
 * Copyright (c) 2017,jv.com.cn All Rights Reserved.
 */
@Component
public class CosScheduler {
    @Autowired
    SchedulerFactoryBean schedulerFactoryBean;

    public void scheduleJobs() throws SchedulerException {
        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        startDownloadJob(scheduler);
    }

    private void startDownloadJob(Scheduler scheduler) throws SchedulerException {
        JobDetail jobDetail = JobBuilder.newJob(DownloadJob.class).withIdentity("DownloadJob", "DownloadGroup").build();
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/5 * * * * ?");
        CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity("DownloadTrigger", "DownloadGroup").withSchedule(
            scheduleBuilder).build();
        scheduler.scheduleJob(jobDetail, cronTrigger);
    }

}
